package com.jiaobuchong.kafka.consumer.group;

/**
 * @author zhoujie
 * Created on 2018-06-17 13:35
 */
import kafka.Kafka;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

import java.util.Arrays;
import java.util.Properties;

public class ConsumerTest {
    public static void main(String[] args) {
        String topicName = "msg.bidding-manage-consumer.async";
        String groupName = "testGroup1";
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "10.21.32.34:9092");
        properties.put("group.id", groupName);
        properties.put("auto.offset.reset", "earliest");
        properties.put("enable.auto.commit", "true");
        properties.put("auto.commit.interval.ms", "1000");
        properties.put("fetch.max.wait.ms", 100);
        properties.put("session.timeout.ms", "30000");
        properties.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        properties.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");

        KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(properties);
        consumer.subscribe(Arrays.asList(topicName));

        while (true) {
//            System.out.println("consumer ing ");
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records) {
                System.out.println(record.value());
            }
            consumer.commitSync();
        }


    }
}